package android.demo.engine;

import android.demo.engine.tasks.Task;
import android.demo.engine.tasks.TaskFactory;
import android.demo.engine.tasks.hardcoded.HardCodedActivityTask;
import android.demo.engine.tasks.hardcoded.HardCodedServiceBinderTask;
import android.demo.engine.tasks.hardcoded.HardCodedServiceStarterTask;
import android.demo.engine.tasks.hardcoded.HardCodedActivityBrowserTask;

/**
 * @author  carlo
 */
public class TaskGraph {
	
	public TaskGraph(){
		TASK_LIST= TaskFactory.getInstance().getTasks();
	}
	public Task getNextTask(int taskId) {
		int previousIndex= getTaskIndex(taskId);
		if(previousIndex==TASK_LIST.length-1)
			return null;
		else
			return getTask(previousIndex+1);
	}
	
	public Task getNextTask(Task task) {
		return getNextTask(task.getId());
	}
	
	/**
	 * @uml.property  name="tASK_LIST"
	 * @uml.associationEnd  multiplicity="(0 -1)"
	 */
	private Task[] TASK_LIST;
	
	private int getTaskIndex(int taskId){//TODO
//		throw new UnknowntaskException("task not found in task list"); //wrong input task
		return taskId;
	}

	public Task getTask(int taskId) {	//TODO
		if(taskId>=0 && taskId<TASK_LIST.length)
			return TASK_LIST[taskId];
		else
			return null;
	}

	public Task getFirstTask() {
		return TASK_LIST[0];
	}
	public Task getPreviousTask(Task previous) {
		if(hasPrevious(previous))
			return getTask(previous.getId()-1);
		else
			return null;
	}
	public boolean hasPrevious(Task next) {
		return next.getId()>0;
	}
	public boolean hasNext(Task previous){
		return previous.getId()<TASK_LIST.length-1;
	}
}
